#!/usr/bin/env python
import sys
import Image
import json
cover = Image.open("input/badcat.png")
w = cover.size[0]
(x, y) = (0, 0)
result = []
for line in sys.stdin:
    line = line.strip()
    list_of_tuples = json.loads(line)
    for element in list_of_tuples:
        result.append(tuple(element))
counter=0
for el in result:
    #if el == (41, 20, 11):
    #    el = (41,20,10)
    #if counter==len(result)-1:
    #    el = (el[0],el[1], el[2]+1)
    cover.putpixel((x, y), el)
    #print el
    if x == w - 1:
        x = 0
        y += 1
    else:
        x += 1
    counter+=1
cover.save("output/pipe_tulemus."+cover.format, cover.format)
